package cn.itsource.org.controller;

import cn.itsource.basic.util.JsonResult;
import cn.itsource.org.domain.Department;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.query.DepartmentQuery;
import cn.itsource.org.query.EmployeeQuery;
import cn.itsource.org.query.ShopQuery;
import cn.itsource.org.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * department控制层
 */
@RestController
@RequestMapping("/shop")
@Api(tags = "部门管理")
public class ShopController {

    @Autowired
    private IShopService shopService;
    /**
     * 查询所有部门接口
     * @return
     */
    @PostMapping("/settlement")
    @ApiOperation(value = "注册店铺",notes = "注册店铺")
    public JsonResult findStory(@RequestBody Shop shop){
        shopService.findStory(shop);
        return JsonResult.createSuccess();
    }
    @GetMapping("/active/{uuid}/{shopId}")
    @ApiOperation(value = "激活店铺",notes = "激活店铺")
    public JsonResult activeStore(@PathVariable("uuid") String uuid,@PathVariable("shopId") String shopId){
        return JsonResult.createSuccess(shopService.activeStore(uuid,shopId));
    }
    /**
     * 查询所有部门接口
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "查询所有店铺",notes = "查询所有店铺")
    public JsonResult findPage(@RequestBody ShopQuery query){
        return JsonResult.createSuccess(shopService.findPage(query));
    }
    @PostMapping("/process")
    @ApiOperation(value = "修改",notes = "可以根据id区分操作")
    public JsonResult saveOrUpdate(@RequestBody Shop shop){

        //根据id区分,没有id就是新增
        try {
            shopService.Update(shop);

            return JsonResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return JsonResult.createError("操作异常,联系管理员李裕");
        }
    }

    /**
     * 删除员工根据id
     * @return
     * 接受请求： /emp/12
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除操作",notes = "根据id删除员工")
    public JsonResult delete(@PathVariable("id") Long id){

        //根据id区分,没有id就是新增
        try {
            //调用删除
            Shop one = shopService.findOne(id);
            shopService.updateState(one);

            return JsonResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return JsonResult.createError("操作异常,联系管理员李裕");
        }
    }
    @PostMapping("/batchRemove")
    public JsonResult batchRemove(@RequestBody ShopQuery query){

        //根据id区分,没有id就是新增
        try {
            //调用删除
            shopService.batchRemove(query);

            return JsonResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return JsonResult.createError("操作异常,联系管理员李裕");
        }
    }

}





